package com.wjsima.renyisima.demo;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

public class Demo {
    public static <T> void doJob(T t, Consumer<T> consumer) {
        consumer.accept(t);
    }
    public static <T> void doJob(T t, Consumer<T> consumer1, Consumer<T> consumer2) {
        consumer1.andThen(consumer2).accept(t);
    }

    public static void main(String[] args) {
        HashMap<String, Integer> map = new HashMap<>();

        //key:姓名 value:成绩
        map.put("岑小村",59);
        map.put("谷天洛",82);
        map.put("渣渣辉",98);
        map.put("蓝小月",65);
        map.put("皮几万",70);
        Consumer<HashMap<String,Integer>> co = map1 -> System.out.println(map1.get("谷天洛"));
        doJob(map,co);
//        b)打印最高分
        Consumer<HashMap<String,Integer>> co1 = new Consumer<HashMap<String, Integer>>() {
            @Override
            public void accept(HashMap<String, Integer> map2) {
                int max = map2.get("岑小村");
                Set<Map.Entry<String, Integer>> entries = map2.entrySet();
                for (Map.Entry<String, Integer> entry : entries) {
                    if (max < entry.getValue()){
                        max = entry.getValue();
                    }
                }
                System.out.println(max);
            }
        };
        doJob(map,co1);
//        打印 60分 和70分为及格线下及格人的名字
        Consumer<HashMap<String,Integer>> co3 = new Consumer<HashMap<String, Integer>>() {
            @Override
            public void accept(HashMap<String, Integer> map) {
                for (Map.Entry<String, Integer> s : map.entrySet()) {

                    if (s.getValue() >= 60){

                        System.out.println("60分为及格线：" + s.getKey());
                    }

                }
            }
        };
        Consumer<HashMap<String,Integer>> co4 = new Consumer<HashMap<String, Integer>>() {
            @Override
            public void accept(HashMap<String, Integer> map) {
                for (Map.Entry<String, Integer> s : map.entrySet()) {

                    if (s.getValue() >= 70){

                        System.out.println("70分为及格线:" + s.getKey());
                    }

                }
            }
        };
        doJob(map,co3,co4);

    }
}
